package com.menggudf.service.impl;

import com.menggudf.entity.MenstruationfertilityHistory;
import com.menggudf.mapper.MenstruationfertilityHistoryDao;
import com.menggudf.service.MenstruationfertilityHistoryService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (MenstruationfertilityHistory)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:31
 */
@Service("menstruationfertilityHistoryService")
public class MenstruationfertilityHistoryServiceImpl implements MenstruationfertilityHistoryService {
    @Resource
    private MenstruationfertilityHistoryDao menstruationfertilityHistoryDao;

    /**
     * 通过ID查询单条数据
     *
     * @param mid 主键
     * @return 实例对象
     */
    @Override
    public MenstruationfertilityHistory queryById(Integer mid) {
        return this.menstruationfertilityHistoryDao.queryById(mid);
    }

    /**
     * 分页查询
     *
     * @param menstruationfertilityHistory 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<MenstruationfertilityHistory> queryByPage(MenstruationfertilityHistory menstruationfertilityHistory, PageRequest pageRequest) {
        long total = this.menstruationfertilityHistoryDao.count(menstruationfertilityHistory);
        return new PageImpl<>(this.menstruationfertilityHistoryDao.queryAllByLimit(menstruationfertilityHistory, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param menstruationfertilityHistory 实例对象
     * @return 实例对象
     */
    @Override
    public MenstruationfertilityHistory insert(MenstruationfertilityHistory menstruationfertilityHistory) {
        this.menstruationfertilityHistoryDao.insert(menstruationfertilityHistory);
        return menstruationfertilityHistory;
    }

    /**
     * 修改数据
     *
     * @param menstruationfertilityHistory 实例对象
     * @return 实例对象
     */
    @Override
    public MenstruationfertilityHistory update(MenstruationfertilityHistory menstruationfertilityHistory) {
        this.menstruationfertilityHistoryDao.update(menstruationfertilityHistory);
        return this.queryById(menstruationfertilityHistory.getMid());
    }

    /**
     * 通过主键删除数据
     *
     * @param mid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer mid) {
        return this.menstruationfertilityHistoryDao.deleteById(mid) > 0;
    }
}
